package ewms.controller;

import java.util.List;
import java.util.Arrays;

import ewms.bo.EwmsWasteInventoryAddBo;
import ewms.bo.EwmsWasteInventoryEditBo;
import ewms.bo.EwmsWasteInventoryQueryBo;
import ewms.service.IEwmsWasteInventoryService;
import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import ewms.common.annotation.RepeatSubmit;
import ewms.common.annotation.Log;
import ewms.common.core.controller.BaseController;
import ewms.common.core.domain.AjaxResult;
import ewms.common.enums.BusinessType;
import ewms.vo.EwmsWasteInventoryVo;
import ewms.common.utils.poi.ExcelUtil;
import ewms.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 危废库存信息Controller
 *
 * @author zhaoxiaochun
 * @date 2022-02-09
 */
@Api(value = "危废库存信息控制器", tags = {"危废库存信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/business/wasteInventory")
public class EwmsWasteInventoryController extends BaseController {

    private final IEwmsWasteInventoryService iEwmsWasteInventoryService;

    /**
     * 查询危废库存信息列表
     */
    @ApiOperation("查询危废库存信息列表")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:list')")
    @GetMapping("/list")
    public TableDataInfo<EwmsWasteInventoryVo> list(@Validated EwmsWasteInventoryQueryBo bo) {
        return iEwmsWasteInventoryService.selectPageWasteInventoryList(bo);
    }

    /**
     * 导出危废库存信息列表
     */
    @ApiOperation("导出危废库存信息列表")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:export')")
    @Log(title = "危废库存信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<EwmsWasteInventoryVo> export(@Validated EwmsWasteInventoryQueryBo bo) {
        List<EwmsWasteInventoryVo> list = iEwmsWasteInventoryService.selectWasteInventoryList(bo);
        ExcelUtil<EwmsWasteInventoryVo> util = new ExcelUtil<EwmsWasteInventoryVo>(EwmsWasteInventoryVo.class);
        return util.exportExcel(list, "危废库存信息");
    }

    /**
     * 获取危废库存信息详细信息
     */
    @ApiOperation("获取危废库存信息详细信息")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:query')")
    @GetMapping("/{wasteInventoryId}")
    public AjaxResult<EwmsWasteInventoryVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("wasteInventoryId") Long wasteInventoryId) {
        return AjaxResult.success(iEwmsWasteInventoryService.queryById(wasteInventoryId));
    }

    /**
     * 新增危废库存信息
     */
    @ApiOperation("新增危废库存信息")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:add')")
    @Log(title = "危废库存信息", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody EwmsWasteInventoryAddBo bo) {
        return toAjax(iEwmsWasteInventoryService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改危废库存信息
     */
    @ApiOperation("修改危废库存信息")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:edit')")
    @Log(title = "危废库存信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody EwmsWasteInventoryEditBo bo) {
        return toAjax(iEwmsWasteInventoryService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除危废库存信息
     */
    @ApiOperation("删除危废库存信息")
    @PreAuthorize("@ss.hasPermi('business:wasteInventory:remove')")
    @Log(title = "危废库存信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{wasteInventoryIds}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] wasteInventoryIds) {
        return toAjax(iEwmsWasteInventoryService.deleteWithValidByIds(Arrays.asList(wasteInventoryIds), true) ? 1 : 0);
    }
}
